import numpy as np
import matplotlib.pyplot as plt
import os
from matplotlib.colors import LogNorm

# define data directory
fname = 'exfig6.npz'

# load npz file
data = np.load(fname, allow_pickle=True)
print(data.files)
#save data to variables
for key in data.files:
    exec(key + " = data['" + key + "']")

# plot
fig, ax = plt.subplots(1, 1, figsize=(6, 5))
fig.suptitle('exfig6')

nx = B_lin.shape[0]
mid = int((nx-1)/2)
lines = []
for m in indices:
    X = B_lin[mid::-1]/(Rxy_asym[mid::-1,m]*1e-3)
    Y = np.square(Rxy_asym[mid::-1,m]*1e-3)
    Tmean = np.mean(T_down[:,m])
    print(Tmean)
    l, = ax.plot(X,Y, label="{:.1f}".format(Tmean) + ' K')
    lines.append(l)
    ax.set_xlabel('$|B/R_{yx}|$ ($\mathrm{T}/\mathrm{k}\Omega$)')
    ax.set_ylabel('$R_{yx}^2$ ($\mathrm{k}\Omega^2$)')
ax.legend()

ax.set_xlim([0,0.5])
ax.set_ylim([-0.01,3.4])
plt.show()